<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>this对象</title>
  </head>
  <body>
    <script>
      /* function fun() {
        console.log(this.name);
      }

      var name = "ff";

      var obj = {
        name: "xxx",
        sayName: fun
      };

      obj.sayName();
      fun(); */
      function Person(name, age) {
        this.name = name;
        this.age = age;
      }

      var per = new Person("孙悟空", 18);

      per.toString = function () {
        console.log(`Person[name=${this.name}], age=${this.age}`);
      };

      console.log(per);
    </script>
  </body>
</html>
